/*
	The MIT License

	Copyright (c) 2008 IFMO/GameDev Studio

	Permission is hereby granted, free of charge, to any person obtaining a copy
	of this software and associated documentation files (the "Software"), to deal
	in the Software without restriction, including without limitation the rights
	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
	copies of the Software, and to permit persons to whom the Software is
	furnished to do so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in
	all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
	THE SOFTWARE.
*/


#pragma once


	
class EMShaderCT : public MPxHwShaderNode {
	public:
						EMShaderCT	( void );
		virtual         ~EMShaderCT	( void );
	
			//	Maya stuff :
		static  void *  creator();
		static  MStatus initialize();
		static  MTypeId id;

		virtual MStatus compute( const MPlug&, MDataBlock& );
		virtual void    postConstructor();

		// Geometry properties :
		virtual int		normalsPerVertex	( void ) { return 3; }
		virtual int		texCoordsPerVertex	( void ) { return 1; }
		virtual int		getTexCoordSetNames ( MStringArray& names ) { return 0; }

		// Batch overrides
		virtual MStatus	glBind		( const MDagPath& shapePath );
		virtual MStatus	glUnbind	( const MDagPath& shapePath );
		virtual MStatus	glGeometry	( const MDagPath& shapePath,
									  int prim,				unsigned int writable,
									  int indexCount,		const unsigned int * indexArray,
									  int vertexCount,		const int * vertexIDs,  const float * vertexArray,
									  int normalCount,		const float ** normalArrays,
									  int colorCount, 		const float ** colorArrays,
									  int texCoordCount,	const float ** texCoordArrays);
									  
		// Overridden to draw an image for swatch rendering.
		virtual MStatus renderSwatchImage	( MImage & image );
		void			drawSwatch			( MGeometryData* pGeomData, unsigned int* pIndexing, 
											  unsigned int  numberOfData, unsigned int  indexCount );
		
	protected:	
		static MStatus	LoadShader	( void );
		MStatus			SetupShader	( void );
		MStatus			ResetShader	( void );
	
			// Attributes
		static MObject  a_normal;
		static MObject  a_diffuse;
		static MObject  a_specular;
		static MObject	a_glow;
		static MObject	a_diffuse_k;

		static EMShaderSource	*shader;
	};	



#if 0
typedef float	float4[4];


class EMShaderBase : public MPxHwShaderNode
	{
	public:
		//	Maya stuff :
		static  void *  creator();
		static  MStatus initialize();
		static  MTypeId id;
		
	public:
						EMShaderBase();
		virtual         ~EMShaderBase();
		void			releaseEverything();

		virtual MStatus compute( const MPlug&, MDataBlock& );
		virtual void    postConstructor();

		// Batch overrides
		virtual MStatus	glBind		( const MDagPath& shapePath );
		virtual MStatus	glUnbind	( const MDagPath& shapePath );
		virtual MStatus	glGeometry	( const MDagPath& shapePath,
									  int prim,
									  unsigned int writable,
									  int indexCount,
									  const unsigned int * indexArray,
									  int vertexCount,
									  const int * vertexIDs,
									  const float * vertexArray,
									  int normalCount,
									  const float ** normalArrays,
									  int colorCount,
									  const float ** colorArrays,
									  int texCoordCount,
									  const float ** texCoordArrays);

		virtual int		normalsPerVertex();
		virtual int		texCoordsPerVertex();
		virtual int		getTexCoordSetNames(MStringArray& names);

		// Overridden to draw an image for swatch rendering.
		virtual MStatus renderSwatchImage	( MImage & image );
		void			drawSwatch			( MGeometryData* pGeomData, unsigned int* pIndexing, unsigned int  numberOfData, unsigned int  indexCount );

	protected:

		void			attachSceneCallbacks( void );
		void			detachSceneCallbacks( void );
		static void		releaseCallback		( void* clientData );

	protected:
		virtual	void	SetupShader			( void );
		virtual void	ResetShader			( void );
		virtual void	LoadShader			( void );

		// Callbacks that we monitor so we can release OpenGL-dependant
		// resources before their context gets destroyed.
		MCallbackId fBeforeNewCB;
		MCallbackId fBeforeOpenCB;
		MCallbackId fBeforeRemoveReferenceCB;
		MCallbackId fMayaExitingCB;
	};
#endif	
